<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
	@session_start();
    require '../src/facebook.php';
	require '../../setting/constant.php';
?>


<?php
	$appId = client_id_facebook;
	$secret = client_secret_facebook;
	$facebook = new Facebook(array(
	  'appId'  => $appId,
	  'secret' => $secret,
	));
	
	
	$a=json_decode($_SESSION['session']);

	$url =  '<div style="display:none"><a id="redirect" href="%s">%s</a></div>';
	$aPermission['req_perms'] = "publish_stream";
	$aPermission['api_key']=$appId;
	
	$nextPage=hostname.'facebook/examples/example.php';
	$user = $facebook->getUser();
	
	if (!$user)
	{
		$loginUrl = $facebook->getLoginUrl();
	?>
	
		<script type="text/javascript">
		
				window.location.href = '<?php echo $loginUrl; ?>';
		
		</script>
	<?php
	}
	else{
		try {
		$me = $facebook->api('/me');
			$profile = http_build_query($me);
		$sUrlCallback = $_SESSION['callback'];
		$security_token = $_SESSION['security_token'];
		unset($_SESSION['callback']);
		$sForm =  <<<EOF
<form action="$sUrlCallback" method="POST" id="yahoo_connect">
	<input name="contact" type="hidden" value="$profile"/>
	<input type="hidden" value="$security_token" name="core[security_token]"/>
	<input name="get_success" type="hidden" value="1"/>
	<input name="service" type="hidden" value="3"/>
</form>
<script language="JavaScript" type="text/javascript">
	window.onload = submitYahoo;
	function submitYahoo()
	{
		document.getElementById('yahoo_connect').submit();
	}
</script>
EOF;
		echo $sForm;
			} catch (Exception $e) {
		echo 'Caught exception: ',  $e->getMessage(), "\n";
		}
						
	}
	?>
